API References
Portfolio
Portfolio Module
Creates classes and functions to analyze a portfolio of stocks.
- The Portfolio class has a number of objects, such as:
file : the transaction file locations
funds : symbols that are considered funds
transactions : the transactions the occured
transaction_history : provides the symbol price history
return_view : provides the return view of the portfolio
There are function in class as well: - perfomance : this function will provide the performance of portfolio
- The Manager class has a number of objects, such as:
portfolios : the portfolios that are managed
There are functions in class as well: - get_summary : this function will provide the summary of all portfolios
- class folioflex.portfolio.portfolio.Manager(config_path, portfolios=None)
Manager is a class that analyzes multiple portfolios.
Parameters
- config_pathstr
path to the portfolio file
- portfolioslist (default is None)
list of portfolios in the Portfolio class to analyze.
- get_return_chart(lookback=None, benchmarks=None)
Get the return chart of manager portfolios.
Useful for plotting returns visually.
Parameters
- lookbackdate (optional)
the date the chart should lookback to. If none we use the min date.
- benchmarkslist (optional)
list of tickers to add as benchmarks
Returns
return_chart : plotly chart
- get_summary(date=None, lookbacks=None)
Get summary of portfolios.
Parameters
- datedate
the date the asset summary should be as of. If none we use the max date.
- lookbackslist (default is None)
the number of days to look back
Returns
- summaryDataFrame
- the summary of portfolios
cash
equity
market value
return
benchmark return
- class folioflex.portfolio.portfolio.Portfolio(config_path, portfolio)
A Portfolio class used to provide analysis of a portfolio.
The class requires a transaction file to be provided. The transaction file will have sales and buys to then develop a return of the portfolio as well as a return of the different assets that were purchased.
There are a number of options that the user can provide to filter the analysis to a particular subset of transactions or brokers. There are also options to provide a list of funds or delisted stocks so that when the ticker price history is downloaded from yahoo finance, the price history is not downloaded and instead use the price of the transactions.
Parameters
- config_pathstr
the location of the config file
- portfoliostr
the name of the portfolio to analyze
- check_tx(tx_df=None)
Check that transactions have correct data.
Parameters
- tx_dfDataFrame
dataframe to performe checks on
Returns
portfolio_checks_failed : int
- get_performance(date=None, tx_hist_df=None, lookback=None, prettify=True)
Get performance of portfolio and stocks traded at certain point of time.
Parameters
- datedate (default is max date)
the date the portfolio performance should be as of. If none we use the max date.
- tx_hist_dfDataFrame (default is all transactions)
dataframe to get return percent from
- lookbackint (default is None)
the number of days to look back (uses a calendar day and not stock)
- prettifybool (default is True)
whether to prettify the output
Returns
- performanceDataFrame
- the performance of individual assets as well as portfolio
date
average price
last price
cumulative units
cumulative cost
market value
return
dwrr return percentage
annualized dwrr return percentage
realized
unrealized
cumulative_dividend
cash
equity
- get_transactions(filter_type=None, filter_broker=None, other_fields=None)
Get the transactions made.
Parameters
- filter_typelist (optional)
list of strings to exclude out of type field. e.g. a dividend type may not want to be included in total
- filter_brokerlist (optional)
list of strings to include out of broker field.
- other_fieldslist (optional)
additional fields to include
Returns
- transactionsDataFrame
the transactions made on portfolio
- get_transactions_history(tx_df, price_history=None, other_fields=None, benchmarks=None)
Get the history of stock transcations by merging transaction and price history.
Parameters
- tx_dfDataFrame
Transactions to calculate metrics on
- price_historyDataFrame
Price history DataFrame
- other_fieldslist (optional)
additional fields to include
- benchmarkslist (optional)
list of tickers to add as benchmarks
Returns
- transactions_historyDataFrame
the price history of stock transactions
- get_view(view='market_value', tx_hist_df=None)
Get the a specific view of the portfolio.
Useful for plotting returns visually.
Parameters
- viewstr
- column to sum over on the portfolio dataframe
e.g. “market_value”, “return”, “cumulative_cost”, “realized”
- tx_hist_dfDataFrame
dataframe to get return percent from
Returns
view_df : DataFrame
Heatmap Module
Heatmap for app.
Provides the heatmap
- folioflex.portfolio.heatmap.get_heatmap(config_path=None, portfolio=None, lookback=None)
Provide figure for heatmap.
Parameters
- config_pathstr (optional)
path to config file
- portfoliostr (optional)
portfolio to get heatmap for, if None use sp500
- lookbackint (optional)
number of days to lookback
Returns
- figFigure
heatmap figure
Wrappers Module
Creates wrappers for different data sources.
The data sources or api may change or become obsolete. This wrapper abstracts the data from the larger portfolio project, and allows easier integration.
- class folioflex.portfolio.wrappers.BLS
Wrapper for bureau of labor statistics.
Class that provides functions that use data from bureau of labor statistics. https://www.bls.gov/cpi/
The api documentation can be found here and using v1 so don’t need an api key: https://www.bls.gov/developers/api_signature.htm
- class folioflex.portfolio.wrappers.Finviz
Wrapper for FinViz data.
Class that provides functions that use data from FinViz data.
- class folioflex.portfolio.wrappers.Fred
Wrapper for federal reserve data.
Class that provides functions that use data from federal reserve.
The api documentation can be found here: https://fred.stlouisfed.org/docs/api/fred/
- class folioflex.portfolio.wrappers.TradingView
Wrapper for Trading View api.
Class that provides functions that use data from TradingView. https://www.tradingview.com
- get_economic_calendar(to_date=None, from_date=None, minImportance=1)
Get the latest economic calendar.
This is sourced from the following site: https://www.tradingview.com/economic-calendar/
Parameters
- to_datestr (optional)
the end date of the calendar - format YYYY-MM-DD default is today
- from_datestr (optional)
the start date of the calendar - format YYYY-MM-DD default is 7 days ago
- minImportanceint (optional)
the minimum importance of the event default is 1
Returns
- calendarDataFrame
DataFrame of economic calendar
- class folioflex.portfolio.wrappers.Web
Wrapper for web data.
Class that provides functions that use data from web data.
- class folioflex.portfolio.wrappers.Yahoo
Wrapper for yahoo finance data.
Class that provides functions that use data from yahoo finance.
- fast_info(ticker)
Get the info for ticker.
Parameters
- tickerstr
symbol to get data for
Returns
- fast_infodict
provides dictionary of info on ticker
- get_change_percent(ticker, days=365)
Get the percentage change of a stock over a given number of days.
Parameters
- tickerstr
the ticker symbol of the stock
- daysint (default=365)
the number of days to go back in time
Returns
- change_percentfloat
the percentage change of the stock over the given number of days
- get_sma(ticker, days=365)
Get the percentage change of a stock over a given number of days.
Parameters
- tickerstr
the ticker symbol of the stock
- daysint (default=365)
the number of days to go back in time
Returns
- smafloat
the simple moving average
- info(ticker)
Get the info for ticker.
Parameters
- tickerstr
symbol to get data for
Returns
- infoDataFrame
provides info on ticker
- most_active(count=25)
Provide a dataframe of the most active stocks for the most recent trading day.
Parameters
- countint (default=25)
number of most active stocks to return
Returns
most_active : DataFrame DataFrame of most active stocks
- news(ticker)
Get the news for ticker.
Parameters
- tickerstr
symbol to get data for
Returns
- newsDataFrame
provides news articles on ticker
Market
Market Module
Market Screeners.
Provides market screeners
Utils
Config Helper Module
Load config.
- folioflex.utils.config_helper.get_config(path)
Get the config path.
Parameters
- pathstr
path to the config file
Returns
- configconfigparser.ConfigParser
the config parser
- folioflex.utils.config_helper.get_config_options(path, section)
Load the configuration options.
Parameters
- pathstr
path to the config file
- sectionstr
the section of the config file to load
Returns
- optionsdict
dictionary of options