Finance Monte-Carlo Simulation using PyTorch
Project description
Finance Monte-Carlo Simulation using PyTorch
- An easy-to-use python package to do Monte-Carlo Simulation on stock prices
- GPU accelerated Monte-Carlo simulation, that could allow simulation more random walkers without a large time penalty
Installation
pip install pyfmc
Geometric Brownian Motion Simulation
Configure the simulation
import pandas as pd
import matplotlib.pyplot as plt
from pyfmc.simulations.gbm import GBM
data_path = "./tests/data/AAPL.csv" # Replace with one's desired data
simulation = GBM(
df=pd.read_csv(data_path),
n_walkers=500_000,
n_steps=100,
n_trajectories=50,
open_index="Open", # Make sure the DataFrame has column index specified here
close_index="Close", # Make sure the DataFrame has column index specified here
)
result = simulation.simulate()
Simulation Results
Price Distribution
price_dist = result.price_distribution()
price_dist.plot(bins=500)
plt.show()
Return Distribution
return_dist = result.return_distribution()
return_dist.plot(kde=True)
plt.show()
Walkers Trajectories
trajectories = result.trajectories()
trajectories.plot()
plt.show()
Value at Risk (VaR)
var = result.VaR(alpha=5)
# output: -0.2515...
# The worst 5% chance -> -25% return
For Development
Python virtual environment:
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txt
Reference
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyfmc-0.1.3.tar.gz
(4.4 kB
view hashes)