A library to calculate derivatives VAR portfolio and generate a report
Project description
VARPORT
VARPORT is a Python library to calculate Value at Risk (VaR) of a derivatives portfolio and generate reports .
Features
- Compute VaR using Monte Carlo simulations
- Generate PDF reports with portfolio summaries and charts
- Supports options and futures portfolios
Installation
#usage
pip install varport
from varport import ReportGenerator, MainVaRProcessor
import numpy as np
# Load your portfolio from a CSV file
portfolio_file = 'C:/xxx/portfolio.csv'
# Example user input for mu and Sigma
mu = np.array([0.05, 0.03, 0.07, 0.04, 0.06]) # Example mu vector (expected returns)
Sigma = np.array([[0.1, 0.02, 0.03, 0.01, 0.04], # Example covariance matrix
[0.02, 0.08, 0.01, 0.03, 0.02],
[0.03, 0.01, 0.09, 0.02, 0.01],
[0.01, 0.03, 0.02, 0.07, 0.02],
[0.04, 0.02, 0.01, 0.02, 0.08]])
# Initialize MainVaRProcessor with the portfolio file path
var_processor = MainVaRProcessor(filepath=portfolio_file)
# Process the portfolio with user-provided mu and Sigma to calculate VaR and differences
portfolio, VaR, differences = var_processor.process(mu=mu, Sigma=Sigma)
# Generate the report with the calculated differences and VaR
report = ReportGenerator(differences=differences, VaR=VaR, portfolio=portfolio)
# Generate and save the PDF report
report.display_table_and_chart(pdf_filename="VaR_Report_Test.pdf")
print("Report generated successfully!")
# Portfolio Management Tool
## Overview
This tool allows users to manage their portfolio of financial instruments such as options and futures. You can upload your portfolio in a CSV file format that follows the required structure outlined below.
---
## Portfolio File Format
The portfolio file should be in `.csv` format and must include the following columns:
### Required Columns:
1. **date** (string, in `dd/mm/yyyy` format):
The date the trade was made.
2. **instrument_type** (string):
Specifies the type of financial instrument. Supported values:
- `option`
- `future`
3. **underlying_asset** (string):
The underlying asset for the trade (e.g., "sugar", "cocoa", "coffee").
4. **quantity** (integer):
The quantity of the asset in the trade. Positive values for long positions, negative values for short positions.
5. **lot_size** (integer):
Lot size for the contract. Typically `1`, but may vary.
6. **option_type** (string, optional for non-option instruments):
Type of option for option instruments. Supported values:
- `put`
- `call`
7. **strike_price** (numeric, optional for non-option instruments):
The strike price of the option contract.
8. **implied_volatility** (numeric):
The implied volatility of the option, typically represented as a decimal.
9. **expiry** (string, in `dd/mm/yyyy` format):
The expiration date of the option or future contract.
10. **underlying_future_expiry** (string, in `dd/mm/yyyy` format, optional for non-futures):
The expiry date of the underlying future, if applicable.
11. **risk_free_rate** (numeric):
The risk-free interest rate assumed in the valuation model, typically expressed as a decimal.
12. **volatility** (numeric):
The actual volatility of the underlying asset, represented as a decimal.
13. **underlying_price** (numeric):
The price of the underlying asset at the time of trade.
---
## Example CSV File
```csv
date,instrument_type,underlying_asset,quantity,lot_size,option_type,strike_price,implied_volatility,expiry,underlying_future_expiry,risk_free_rate,volatility,underlying_price
13/04/2023,option,sugar,27,1,put,200,0.478477817,31/10/2025,30/04/2025,0.031413423,0.215497254,429.494494
15/12/2023,option,cocoa,-83,1,call,300,0.41251842,30/04/2025,31/01/2025,0.019328656,0.17107249,478.6526844
28/09/2023,future,sugar,-76,1,,,0.472371642,31/08/2025,30/04/2025,0.028958798,0.206371496,467.5348595
...
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
varport-0.1.1.tar.gz
(11.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
varport-0.1.1-py3-none-any.whl
(11.0 kB
view details)
File details
Details for the file varport-0.1.1.tar.gz.
File metadata
- Download URL: varport-0.1.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73c2f51bbb3fb9145b054281dd9bfe55311afc8d18baddf9feadb6b529acf4b4
|
|
| MD5 |
3dd0287b033ec1f7957314e5315fe17f
|
|
| BLAKE2b-256 |
04376307b961deb65eb01bea111479ee0362c642c1ce6d1abf2507a13d5c5ec4
|
File details
Details for the file varport-0.1.1-py3-none-any.whl.
File metadata
- Download URL: varport-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
643c05f8973a5724c5ea60ca8a99abb639d6319805254e48855bbc68256cfe5f
|
|
| MD5 |
e360dcc87f4642577b8395465e6b9eb6
|
|
| BLAKE2b-256 |
56698031f3089f802ce28f80c7d74fd2795117ea798655b0b174dfc3056b41d0
|