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 once, deploy globally, and scale automatically with built-in access to all the financial data you need.
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.
Automatic Data Access
The data you need is automatically available to all your cloud functions without any configuration or setup.
Write Functions
Create serverless financial cloud functions with built-in access to all your data and APIs.
Scale Automatically
Your functions scale from zero to millions of executions automatically, with no infrastructure to manage.
Ready to scale your financial computations?
Start building scalable 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::{encoding, plugin_fn, FnResult, Json, ToBytes};
use ndarray::Array1;
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: &Array1<f64>, y: &Array1<f64>) -> f64 {
let x_mean = x.mean().unwrap();
let y_mean = y.mean().unwrap();
let numerator = x.iter()
.zip(y.iter())
.map(|(&xi, &yi)| (xi - x_mean) * (yi - y_mean))
.sum::<f64>();
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<f64>) -> FnResult<Output> {
let correlation = pearson_correlation(
&Array1::from_iter(fin_data.get_candles("symbol_1")?
.windows(2)
.map(|w| (w[1].close / w[0].close).ln())),
&Array1::from_iter(fin_data.get_candles("symbol_2")?
.windows(2)
.map(|w| (w[1].close / w[0].close).ln())),
);
Ok(Output {correlation})
}