Crate finalytics
source ·Expand description
§Finalytics
Welcome to finalytics
, financial analytics in Rust!
finalytics
is a Rust library designed for retrieving financial data and performing security analysis and portfolio optimization.
§Installation
Add the following to your Cargo.toml
file:
[dependencies]
finalytics = "*"
Or run the following command:
cargo install finalytics
§Models
These are the main Interfaces for accessing the finalytics
library methods
§Ticker - Retrieve and analyze ticker data
§Tickers - Retrieve and analyze multiple tickers
§Portfolio - Optimize a portfolio of tickers
§Example
use finalytics::prelude::*;
use polars::prelude::*;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Instantiate a Multiple Ticker Object
let ticker_symbols = Vec::from(["NVDA", "GOOG", "AAPL", "MSFT","BTC-USD"]);
let tickers = TickersBuilder::new()
.tickers(ticker_symbols)
.start_date("2020-01-01")
.end_date("2024-01-01")
.interval(Interval::OneDay)
.benchmark_symbol("^GSPC")
.confidence_level(0.95)
.risk_free_rate(0.02)
.build();
// Calculate the Performance Statistics
let performance_stats = tickers.performance_stats().await?;
println!("{:?}", performance_stats);
// Display the Security Analysis Charts
tickers.returns_chart(None, None).await?.show();
tickers.returns_matrix(None, None).await?.show();
// Perform a Portfolio Optimization
let portfolio = tickers.optimize(Some(ObjectiveFunction::MaxSharpe), None).await?;
println!("{:?}", portfolio.performance_stats);
// Display the Portfolio Optimization Charts
portfolio.performance_stats_table(None, None)?.show();
portfolio.optimization_chart(None, None)?.show();
portfolio.performance_chart(None, None)?.show();
portfolio.asset_returns_chart(None, None)?.show();
Ok(())
}