def test_Setters(self): test_asset = Asset(a_name='myAsset', assetType='fund') test_asset.assetName = 'myAsset2' test_asset.assetType = 'etf' mydf = pd.DataFrame({'Data': [1, 2, 3], 'Other': [23, 32, 34]}) # Test AssetDF with self.assertRaises(TypeError): test_asset.assetDf = 'mydf' with self.assertRaises(ValueError): test_asset.assetDf = pd.DataFrame() test_asset.assetDf = mydf self.assertIsInstance(test_asset.assetDf, pd.DataFrame) returns = [1, 2, 3, 4] test_asset.assetStdDeviation = returns # Test asset Name self.assertEqual(test_asset.assetName, 'myAsset2') with self.assertRaises(TypeError): test_asset.assetName = ['myname'] # Test asset Type self.assertEqual(test_asset.assetType, 'etf') with self.assertRaises(TypeError): test_asset.assetType = ['myname'] with self.assertRaises(ValueError): test_asset.assetType = 'etf2' # Test Allocation with self.assertRaises(TypeError): test_asset.allocation = 1000 with self.assertRaises(ValueError): test_asset.allocation = 0.0 # Test Initial Inversion with self.assertRaises(TypeError): test_asset.initial_inversion = 0.25 with self.assertRaises(ValueError): test_asset.initial_inversion = 0 # Test Sharpe Ratio myReturns = pd.Series([1.5, 2, 4.1, 5]) test_asset.sharpeRatio = myReturns self.assertEqual(round(test_asset.sharpeRatio, 2), 3.77) with self.assertRaises(TypeError): test_asset.sharpeRatio = 3
def test_getters(self): test_asset = Asset(a_name='myAsset', assetType='fund') self.assertIs(test_asset.assetName, 'myAsset') self.assertIs(test_asset.assetType, 'fund') myDf = pd.DataFrame({'Col 1': [1, 2], 'Col 2': [3, 4]}) test_asset.assetDf = myDf self.assertIsInstance(test_asset.assetDf, pd.DataFrame) self.assertIs(test_asset.assetDf, myDf) test_asset.allocation = 0.30 self.assertIsInstance(test_asset.allocation, float) self.assertEqual(test_asset.allocation, 0.30) test_asset.sharpeRatio = pd.Series([1, 2, 3, 4]) self.assertIsInstance(test_asset.sharpeRatio, float) test_asset.initial_inversion = 1000 self.assertEqual(test_asset.initial_inversion, 1000)