Skip to main content

A package used for portfolio analysis in Fintech512

Project description

Introduction

This package is used for portfolio analysis in FINTECH 512 Bigbucks project. This package also depends on the bigbucks_db package to interact with the supabase database and Alpha Vantage.

Connect to supabase and alpha Vantage

# Connect to supabase
SUPABASE_URL = ""
KEYS = ""
objs = Table_View(SUPABASE_URL, KEYS)

# Connect to Alpha Vantage
STOCK_API_KEYS = ""
objs_realtime = Buy_And_Sell(STOCK_API_KEYS)

Import package

from bigbucks_port.portfolio import *

Functions

  • Get the current portfolio holdings for user. It returns a json list includes the stock symbol, number of shares and price per share (weighted by historical cost) Note: If you want to get all the stocks for all the users, set id=None. Same for other functions below.
holding = current_holding(objs,6)

Example output:

[{"stock_symbol":"AAPL","num_shares":0,"pv":0.0,"price per share":null},{"stock_symbol":"IBM","num_shares":100,"pv":13107.0007324219,"price per share":131.0700073242}]
  • Calculate the expected return, std and covariance of portfolio The statistics are calculated based on the historical data. Note: It returns 4 values, the fourth one is the json list with expected return and std for each stock and the rest 3 are used in later functions.
er,std,covar,er_std_json = er_covar(objs,6)

Example output of er_std_json

{"mean":{"AAPL":0.2318697889,"IBM":-0.0075799068},"std":{"AAPL":0.3361717704,"IBM":0.2759977582}}
  • Get the risk and return for a list of portfolios with randomly generated weights
# N: number of portfolios generated
return_risk = rand_scatter(5,objs,6)

Example output

{"mean": [0.13009300157209497, 0.02497749995225248, 0.16554410436129516, 0.14454572030763208, 0.10086096141188186], "std": [0.06705431545265916, 0.0656856601122741, 0.07160084144613905, 0.0686922284906061, 0.06474888518469718]}
  • Get the risk and return for the efficient frontier
return_risk = frontier(objs,6)

Example output

{"mean": [],"std":[]}
  • Get the optimal portfolio given a risk free rate
opt = optimize_port(0.0025,objs,6)

Example output

{"opt mean": 0.2318697888966346, "opt std": 0.08412521675427394, "opt sharpe": 2.7265283555418782}
  • Get the risk and return for the current portfolio Note: weight is calculated by the current holding
risk_return = cur_risk_return(0.0025,objs,6)

Example output

{'mean': -0.007579906778486523, 'std': 0.06906698680510652, 'sharpe': -0.1459439197330273}
  • Calculate the holding period return and balance
holding_stat = holding_return(objs,6,objs_realtime)

Example output

# PV: the market value of all cash and stocks in the account
# Cash: cash remained in the account balance
{'PV': 1000000.0, 'Cash': 986892.9992675781, 'Holding period return': 0.0}

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

bigbucks_port-0.0.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

bigbucks_port-0.0.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file bigbucks_port-0.0.3.tar.gz.

File metadata

  • Download URL: bigbucks_port-0.0.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for bigbucks_port-0.0.3.tar.gz
Algorithm Hash digest
SHA256 99a82b6b90e849a470e90aa79db1aca2ccbd8bc8e65b57631a930b285adba42c
MD5 9ddc99fc1f17713d9f3ed19cb1c8d56d
BLAKE2b-256 8020209cd6d2300463d083094a63ca3385ae7c133210572dae2c0379f20fc455

See more details on using hashes here.

File details

Details for the file bigbucks_port-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bigbucks_port-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4231c8e85540bfc9191671f160da4bb730ff78c7827b401fe7259de85d7f3f28
MD5 76e7aab9f03d25cbf9532e3e88523441
BLAKE2b-256 d868c3ad98578224540d5695feb794629cc57105f76be00f740af438ec56f483

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page