Stock Operations

Imagine you want to buy/sell some instruments on the stock market. Would you invest in the Financial Sector? Maybe buy some blue chips in the Tech Sector?

Anyways, you will need to see how your portfolio looks in various scenarios... Your task is to implement the math and build the GUI to use it! 

Representation

Based on this input, create a representation for your portfolio. A portfolio can have a number of grouping levels and various number of assets on the leaf level.

In this input there are only 3 (including Total) grouping levels, but your solution should support any level of groupings.

All the names are unique, you can think of them as identifiers. All values are given in USD.

Input

input.json

Tasks

The following tasks are incremental, meaning you might not have to use all of the attributes to solve a task.

Task 1 - sum

Provide the grand total value of your portfolio. The grand total is equal to all leaf values summarized.

Task 2 - Rebalance

Before we can define the rebalance as a function we have to cover locks.

In the input JSON you can find the attribute "locks" which will contain a list of names. The name can represent either a grouping or an asset.

When an asset is locked it means that its value must always remain the same during rebalance. (algorithm later on)

When a group is locked it means that the sum of its children must remain the same during rebalance. The non-locked children's value can be changed within a locked group.

...
"locks": ["Media"] //Grouping with the name 'Media' must fix it sum value.
...
{
  "name": "Media", //sum = 4800 USD (3300 + 500 + 1000)
  "items": [
    {"name": "Walt Disney", "value": "3300 USD"},
    {"name": "Twentieth-First Century Fox", "value": "500 USD"},
    {"name": "Comcast", "value": "1000 USD"}
  ]
}
Rebalancing:

You can specify a group or an asset of which's value you can change. As your portfolio has a grand total value, to do so you have either sell or buy other assets accordingly.

If you want to increase the value of an asset you have to decrease proportionally others, while you take your locks into consideration.

If you want to decrease the value of an asset, you have to increase others the same way.

If you want to increase a group, you have to decrease other assets outside of the group and increase the children proportionally within.

if you want to decrease a group you have to increase the other assets and decrease within.

Remember, the grand total of your portfolio should remain the ~same, within the +/-1% margin (Just to make life simpler).

The input contains multiple rebalances. These rebalance requests are in order and should be applied sequentially, one at a time. Each rebalance works with the result of the previous rebalance.

...
"locks": ["Media"] //Media is locked, meaning it is fixed in value, so there is no need to rebalance other assets outside of it.
"rebalance": [{"name": "Comcast", "delta": "-400 USD"}] // Sell 400 USD worth of Comcast
...
{
  "name": "Media", //sum = 4800 USD after rebalance we have to keep this value +/-1%
  "items": [ //As we are selling 400 USD Comcast, we have to buy proportionally from the other assets to maintain the locked 'Media' sum value
    {"name": "Walt Disney", "value": "3300 USD"}, //its proportion of assets that share the additional value: 3300 / (4800 - 1000) = 86.84%, new value = 0.8684 * 400 + 3300 = 3647.36 USD
    {"name": "Twentieth-First Century Fox", "value": "500 USD"}, //proportion it gets from the 400 USD is: 13.15%, new value = 552.6 USD
    {"name": "Comcast", "value": "1000 USD"} // -400 USD is sold the new value has to be: 600 USD
  ]
}

After rebalance the 'Media' sum is: 3647.36 + 552.6 + 600 = 4799.96 USD which is within the tolerance.

Please keep in mind that in case Media is not locked, that would mean that other assets outside of Media would have been also changed.

If you have any further questions for this task do not hesitate to drop by and ask us!

Task 3 - Tree Table View

This is a UI task. In terms of technology and design we do not have hard requirements, we would like to see a view that has the following properties:

  • Visualize the data in a tree table view format
  • First column of the table is the group column
  • Second column contains values. For assets its own value, for groups the sum of its children
  • Group rows should be expandable/collapsible
Task 4 - Bar chart

Visualize the data in a bar chart that supports drilldowns on groups.

Task 5 - Put Everything Together

If you reached this task you are probably already a Rockstar. Let's make all the puzzle pieces into a nice picture.

So far you have:

  • A working representation
  • A way to summarize group level values
  • You can rebalance with locks
  • You can represent the input in the form of a table/bar chart

The final task is to make your tree table view functional. You can lock cells and edit them which will rebalance other values within the table using the logic of task2.

You should be able to switch to a bar chart (task4) to represent the current data in the table.

algorithm visualization fintech

Criteria

  • Task 1 - Sum:
  • 1 point
  • Task 2 - Rebalance:
  • 3 points
  • Task 3 - Tree Table View
  • 2 points
  • Task 4 - Bar Chart:
  • 2 points
  • Task 5 - Put Everything Together:
  • 2 points

Submission

For task 1-2 you can submit your solution in a JSON:

{
 "task1": "$SUM_HERE USD",
 "task2": { ... } //Input JSON with updated values after rebalances applied to it sequentially
}

For task 3-5: Drop by our stand and show your application to us! We are extremely interested!

In this case the application itself is more than enough, no need for the JSON.
We also provide points for partial solutions of tasks so even if you could not finish one, drop by and show us what you have!