Skip to content

A Julia package for selecting assets based on volume, volatility, and market cap. Supports multiple selection methods for financial analysis.

License

Notifications You must be signed in to change notification settings

shayandavoodii/PickAssets.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage

This package aims to provide tools for creating a dataset from a universe of assets based on different criteria, such as the average volume, the average volatility, etc. during various time spans. The package is yet in its early stages and it is under development.

Introduction

Researchers use certain datasets to analyse the performance of their proposed model or strategy (some examples are provided in the pictures below). These datasets are usually created from a universe of assets based on different criteria. For example, one might want to create a dataset from a universe of stocks based on the average/highest/lowest volume or volatility or market cap, etc. during various time spans. This package aims to provide tools for creating such datasets using a function called pickassets.
alt text alt text
alt text alt text

Installation

You can install the package by running the following command in the Julia REPL:

using Pkg
Pkg.add(url="github.com/shayandavoodii/PickAssets.jl.git")

Usage

As mentioned earlier, the main function of this package is pickassets. The function takes the following arguments:
  1. An object of type Method. This object specifies the method used to pick the assets. The available methods are:
    • HighVolume: Picks the assets with the highest average volume during the specified time span.
    • HighVolatility: Picks the assets with the highest average volatility during the specified time span.
    • RandomWise: Picks m assets randomly from the passed Vector of assets.
    • MarketCap: Picks the assets with the highest current market capitalization.
  2. A Vector of assets. This Vector should contain the names of the assets that you would like to create the dataset from.

The HighVolume and HighVolatility methods take the following additional arguments in order to specify the time span:

  1. val: The values you intend to use for creating the dataset. I.e., the close price values of the assets (for the HighVolatility method), and the volume values of the assets (for the HighVolume method).
  2. dates: The dates corresponding to the values passed in the val argument.
  3. partition: The partition method used to partition the data. As of now, the DateBased and ValueBased methods are available which can be used in Yearly, Monthly, or Seasonally spans. The DateBased method partitions the data based on the dates passed in the dates argument, while the ValueBased method partitions the data based on the values passed in the val argument. For example, if you pass the Yearly span to the DateBased method, the data will be partitioned into yearly spans based on the dates passed in the dates argument. The ValueBased method will partition the data into yearly spans based on the value passed to the time span. For example, if you pass the Yearly(252) span to the ValueBased method, the data will be partitioned into yearly spans each containing 252 values.

Example

The following example demonstrates how to use the pickassets function to create datasets from a universe of assets based on the various configurations:
using PickAssets, Dates

# A Matrix of close price values of the assets of size (n, m)
# where n is the number of assets and m idicates the number of days.
close_prices = rand(10, 1000)
# A Vector of dates corresponding to the close price values
dates = [Date(2021, 1, 1) + Day(i) for i in 1:1000]
# A Vector of asset names
assets = ["Asset$i" for i=1:10]

# Dataset1: Picks the assets with the highest average volume in yearly time span based on the dates:
dataset1 = pickassets(HighVolume(close_prices, dates, DateBased(Yearly())), assets)

# Dataset2: Picks the assets with the highest average volume in yearly time span based on the values:
dataset2 = pickassets(HighVolume(close_prices, dates, ValueBased(Yearly(252))), assets)

# Dataset3: Picks the assets with the highest average volatility in monthly time span based on the dates:
dataset3 = pickassets(HighVolatility(close_prices, dates, DateBased(Monthly())), assets)

# Dataset4: Picks the assets with the highest average volatility in monthly time span based on the values:
dataset4 = pickassets(HighVolatility(close_prices, dates, ValueBased(Monthly(21))), assets)

# Dataset5: Picks 5 assets randomly from the universe of assets:
dataset5 = pickassets(RandomWise(5), assets)

# Dataset6: Picks the first 3 assets with the highest market capitalization:
using YFinance
assets = tickers = ["CSCO", "RY", "SHOP", "TD", "ENB", "BN"]
dataset6 = pickassets(MarketCap(3), assets)

After retrieving the superior tickers in terms of the specified method, one can use the following field of the returned PickedAssets object to construct the dataset:

# For the first dataset, `dataset1`:
close_prices[dataset1.idx, :]
The output of the pickassets function is an object of type PickedAssets which contains the following fields:
  • mean: The mean of the performed method on val. I.e., the overal average of volatility (for the HighVolatility method) or volume (for the HighVolume method) over all partitions. The picked assets have definitely higher values than the mean.
  • sup: The Vector of superior tickers.
  • idx: The Vector of indexes of the superior tickers in the original Vector of assets. This can help you to find the superior tickers in the original Vector of assets.
  • res: A Dict of the superior tickers and their corresponding values. This provides an overview of all tickers and their corresponding values.
dataset1.mean
# 0.49894928681020795

dataset1.sup
# 4-element Vector{String}:
#  "Asset2"
#  "Asset4"
#  "Asset10"
#  "Asset1"

dataset1.idx
# 4-element Vector{Int64}:
#   1
#   2
#   4
#  10

dataset1.res
# Dict{String, Float64} with 10 entries:
#   "Asset8"  => 0.481928
#   "Asset7"  => 0.498171
#   "Asset2"  => 0.508003
#   "Asset5"  => 0.497606
#   "Asset6"  => 0.492131
#   "Asset4"  => 0.507848
#   "Asset9"  => 0.495822
#   "Asset10" => 0.50147
#   "Asset3"  => 0.491802
#   "Asset1"  => 0.514713

License

This package is released under the MIT License. Please see the LICENSE file for more information.

About

A Julia package for selecting assets based on volume, volatility, and market cap. Supports multiple selection methods for financial analysis.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages