semvec/pypi-packages huggingface dataset:
bigbucks-portfolio 0.1
A package used for portfolio analysis in Fintech512

## 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
```python
# 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)
```

## 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. 

```python
holding = current_holding(objs,6)
```
Example output:
```python
[{"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.

```python
er,std,covar,er_std_json = er_covar(objs,6)
```
Example output of `er_std_json`
```python
{"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

```python
# N: number of portfolios generated
return_risk = rand_scatter(5,objs,6)
```
Example output
```python
{"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
```python
return_risk = frontier(objs,6)
```
Example output
```python
{"mean": [],"std":[]}
```

- Get the optimal portfolio given a risk free rate

```python
opt = optimize_port(0.0025,objs,6)
```
Example output
```python
{"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

```python
risk_return = cur_risk_return(0.0025,objs,6)
```
Example output
```python
{'mean': -0.007579906778486523, 'std': 0.06906698680510652, 'sharpe': -0.1459439197330273}
```

- Calculate the holding period return and balance
```python
holding_stat = holding_return(objs,6,objs_realtime)
```

Example output
```python
# 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}
```
pybpa 0.10.4
A BPA file(dat/swi) resolver. The author wish to thank ZHU Siting for her contribution to the project. Her work has advanced the project's resolution of real industrial systems.
Requires Python: >=3.6

# pybpa
解析PSD-BPA软件中.dat文件和.swi文件的工具，同时包含了对pfo/swx文件的解析，可用于数据集的解析和生成。
包含两个顶层类，dat和swi，基本组成单位为_card，对应文件的每一行。

_card由若干字段和字段对应的值组成，通过get_value方法可以获得字段的值，比如对于某个节点卡，bus_card.get_value(BASE)可以获得节点基准电压。
dat,swi,_card都支持str()方法，会相应地输出为字符串形式的文件或者行。

所有的节点、发电机、线路等电气对象拥有唯一uid，详见uid文件。这些对象分别存储在dat和swi对象的list类型的属性中，uid对应的唯一索引可以在相应的_name属性中查询到。

欢迎试用和交流看法。
持续更新中。

# pybpa的世界观
bpa的使用模式为：
 - 实际系统用dat和swi描述，这两个文件可以认为是由许多行组成，每行是一张bpa卡（我们将空行进行特别处理，保留其作为提升可读性的分隔符的作用，但不进入复杂的解析环节）。
 - 实际系统的元件用一张或者多张卡描述，元件的属性对应卡的字段，元件的属性的读写按照bpa说明书规定的Fortran格式进行。

对应地，pybpa有层次地处理这个系统：
 - 用文件建模系统(dat/swi类)：提供了按行(卡)的索引和组织形式，建立文件行-卡的联系。
 - 用uid组织元件：提供了每个元件在pybpa里的唯一uid，建立卡-元件之间的联系。
 - 卡的读写(init/get/set)由基类_Card提供，卡中字段的读写由基类_Field提供，建立卡字段-元件对象的联系。
 - 最终实现，可以在元件层面操作属性，并发布到文件。
 - 注意上述联系是有限制的。pybpa项目出发点是更方便地操作bpa文件，并不指望读取这些元件并建立一个系统。