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, historical cost and price per share.
  • If you want to get all the stocks for all the users, set id=None. Same for other functions below.
id =6
holding = holding_json(objs,id)

Example output:

{"IBM":{"num_shares":100,"historical_cost":13107.0007324219,"price_per_share":131.0700073242}}

Calculate the historical daily return for each stock in the holding

returns = return_json(objs,id)

Example output:

[{"Symbol": "AAPL", "labels": ["2018-04-03", "2018-04-04"], "data": [{"date": "2018-04-03", "return": 0.010206911067964735}, {"date": "2018-04-04", "return": 0.01894174279199366}]}, {"Symbol": "IBM", "labels": ["2018-04-03", "2018-04-04"], "data": [{"date": "2018-04-03", "return": -0.0014670581452283652}, {"date": "2018-04-04", "return": 0.028096725995288337}]}]

Calculate the historical daily return for SPY

returns = spy_json(objs)

Example output:

{"Symbol": "SPY", "labels": ["2018-04-10", "2018-04-11"], "data": [{"date": "2018-04-10", "return": 0.016588598996312102}, {"date": "2018-04-11", "return": -0.005540685772461173}]}

Calculate the expected return and std of each stock in the portfolio

  • It returns a a json list of mean and std for each stock
er_std = er_std_json(obj,id)

Example output:

{"AAPL":{"mean":0.2318697889,"std":0.3361717704},"IBM":{"mean":-0.0075799068,"std":0.2759977582}}

Get the risk and return for the efficient frontier

# num: number of portfolios on the efficient frontier
return_risk = frontier_json(objs,id,num)

Example output

{"data": [{"std": 0.06906698680510652, "mean": -0.007579906778486523}, {"std": 0.06906698680510652, "mean": -0.007579906778486523}]}

Get the optimal portfolio given a risk free rate

# rf: risk free rate
opt = optimize_port(rf,objs,id)

Example output

{"opt mean": 0.2318697888966346, "opt std": 0.08412521675427394, "opt sharpe": 2.7265283555418782}

Calculate the risk, return and sharpe for 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 cash 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': 1000106.999206543, 'Cash': 986892.9992675781, 'Holding_return': 0.00010699920654300143}

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.7.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

bigbucks_port-0.0.7-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bigbucks_port-0.0.7.tar.gz
  • Upload date:
  • Size: 6.0 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.7.tar.gz
Algorithm Hash digest
SHA256 7668eb3b4b6620000aaea8665614ed6507c206403eb014dabc7f6fd08163ca17
MD5 d8350d806c221b76cc7f9f3c82832f35
BLAKE2b-256 1b07b223833e4d2fda105edba4a5c4f16b7983a7e103bb369ec6e6eb19b00ab3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bigbucks_port-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ca9329b88ed4351a5a8ef2bcd8f35a4d909698fd838ce49170589901ec8aaf70
MD5 ff321a1c7a2111ee8979a941b2b9a5ea
BLAKE2b-256 a59882fcb56020e121233badaecd7bd5ff4538c979e0b4d61b7431ae6fc9afa2

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