Financial Computations at Scale
Write serverless financial cloud functions that scale from zero to millions of executions with instant access to all the data you need.
Financial Cloud Functions
Write functions that scale automatically and react to real-time data changes.
Serverless Financial Computing at Global Scale
Exchange Outpost lets your team write financial cloud functions that scale automatically and have instant access to all the financial data you need.
Write once, scale infinitely
Exchange Outpost makes it easy for your team to build financial cloud functions that scale automatically.
Write Functions
Write a function in any supported language and push it to github in either a public or private repository.
Run Functions
Execute function batches via the the API, the data you request will automatically be provided to your functions.
Create Pegged Functions
Pegged functions listen to real-time data streams, so your computations always reflect the latest information, no manual scheduling or polling required.
Ready to scale your financial computations?
Start building effortless financial computations today.
By signing up, you agree to our Terms & Conditions
Write financial cloud functions in minutes
Get started with our sample templates or build your own custom functions.
mod exchange_outpost;
use crate::exchange_outpost::FinData;
use extism_pdk::{FnResult, Json, ToBytes, encoding, plugin_fn};
use serde::Serialize;
#[derive(Serialize, ToBytes)]
#[encoding(Json)]
pub struct Output {
correlation: f64,
}
/// Calculate the Pearson correlation coefficient between two stock price series
fn pearson_correlation(x: &[f64], y: &[f64]) -> f64 {
let x_mean = x.iter().sum::<f64>() / x.len() as f64;
let y_mean = y.iter().sum::<f64>() / y.len() as f64;
let numerator: f64 = x.iter()
.zip(y.iter())
.map(|(&xi, &yi)| (xi - x_mean) * (yi - y_mean))
.sum();
let denominator_x = x.iter()
.map(|&xi| (xi - x_mean).powi(2))
.sum::<f64>()
.sqrt();
let denominator_y = y.iter()
.map(|&yi| (yi - y_mean).powi(2))
.sum::<f64>()
.sqrt();
numerator / (denominator_x * denominator_y)
}
#[plugin_fn]
pub fn run(fin_data: FinData) -> FnResult<Output> {
let ticker_1 = fin_data.get_ticker("symbol_1")?;
let ticker_2 = fin_data.get_ticker("symbol_2")?;
let x: Vec<f64> = ticker_1.candles.windows(2)
.map(|w| (w[1].close / w[0].close).ln())
.collect();
let y: Vec<f64> = ticker_2.candles.windows(2)
.map(|w| (w[1].close / w[0].close).ln())
.collect();
let correlation = pearson_correlation(&x, &y);
Ok(Output { correlation })
}