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
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.6.tar.gz
(4.5 kB
view details)
File details
Details for the file pyfmc-0.1.6.tar.gz
.
File metadata
- Download URL: pyfmc-0.1.6.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.31.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02c8cb4a9d01a7644b88a6813736f3939add977505c94eb1cb84e2c659941927 |
|
MD5 | 3f35a1180cda1ebb6c8f8ef709ceaf9d |
|
BLAKE2b-256 | a43ac02607253f36849318965fb0298d260a482614499ab26cbbff235b45e51b |