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 add finalytics§Models
These are the main Interfaces for accessing the finalytics library methods
§KLINE - load historical price data from csv, json or dataframe
§Ticker - Retrieve and analyze ticker data
§Tickers - Retrieve and analyze multiple tickers
§Portfolio - Optimize and analyze a portfolio of tickers
§Screener - Screen for stocks, ETFs, indices, mutual funds, futures and cryptocurrencies
§Example
use finalytics::prelude::*;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// 1. Screener — Large-Cap NASDAQ Technology Stocks with ROE >= 15%
let screener = Screener::builder()
.quote_type(QuoteType::Equity)
.add_filter(ScreenerFilter::EqStr(
ScreenerMetric::Equity(EquityScreener::Exchange),
Exchange::NASDAQ.as_ref(),
))
.add_filter(ScreenerFilter::EqStr(
ScreenerMetric::Equity(EquityScreener::Sector),
Sector::Technology.as_ref(),
))
.add_filter(ScreenerFilter::Gte(
ScreenerMetric::Equity(EquityScreener::MarketCapIntraday),
10_000_000_000.0,
))
.add_filter(ScreenerFilter::Gte(
ScreenerMetric::Equity(EquityScreener::ReturnOnEquity),
0.15,
))
.sort_by(
ScreenerMetric::Equity(EquityScreener::MarketCapIntraday),
true,
)
.size(10)
.build()
.await?;
screener.overview().show()?;
screener.metrics().await?.show()?;
// 2. Ticker
let ticker = Ticker::builder()
.ticker("AAPL")
.start_date("2023-01-01")
.end_date("2024-12-31")
.interval(Interval::OneDay)
.benchmark_symbol("^GSPC")
.confidence_level(0.95)
.risk_free_rate(0.02)
.build();
ticker.report(Some(ReportType::Performance)).await?.show()?;
ticker.report(Some(ReportType::Financials)).await?.show()?;
ticker.report(Some(ReportType::Options)).await?.show()?;
ticker.report(Some(ReportType::News)).await?.show()?;
// 3. Tickers
let tickers = Tickers::builder()
.tickers(vec!["NVDA", "GOOG", "AAPL", "MSFT", "BTC-USD"])
.start_date("2023-01-01")
.end_date("2024-12-31")
.interval(Interval::OneDay)
.benchmark_symbol("^GSPC")
.confidence_level(0.95)
.risk_free_rate(0.02)
.build();
tickers.report(Some(ReportType::Performance)).await?.show()?;
// 4. Portfolio — Optimization with Out-of-Sample Evaluation
let mut portfolio = Portfolio::builder()
.ticker_symbols(vec!["NVDA", "GOOG", "AAPL", "MSFT", "BTC-USD"])
.benchmark_symbol("^GSPC")
.start_date("2022-01-01")
.end_date("2024-12-31")
.interval(Interval::OneDay)
.confidence_level(0.95)
.risk_free_rate(0.02)
.objective_function(ObjectiveFunction::MaxSharpe)
.build().await?;
portfolio.optimize()?;
portfolio.report(Some(ReportType::Optimization)).await?.show()?;
portfolio.update_dates("2025-01-01", "2026-01-01").await?;
portfolio.performance_stats()?;
portfolio.report(Some(ReportType::Performance)).await?.show()?;
Ok(())
}