giv2giv / do-not-use-neography

RESTful webservice, powered by Neo4J and written in Ruby
1 stars 0 forks source link

Dwolla: Funds tracking #8

Open michaelblinn opened 11 years ago

michaelblinn commented 11 years ago

We track the movement of funds across the giv2giv platform using relationships in neo4j

Included:

This issue requires tight coupling with Dwolla payment processing.

michaelblinn commented 11 years ago

funds_tracking.rb created with first framework for tracking the movement of funds

michaelblinn commented 11 years ago

Still to do: Begin fleshing out reporting requirements and write the cypher query functions Hook this code into Dwolla webhooks when funds are processed Testing testing - ensure incoming has variable 'data' translates correctly to neo4j node/relationship properties

michaelblinn commented 11 years ago

Endowment share price, shares outstanding nodes & indexes created. These are made endowment-by-endowment, so we'll have a lot of indexes

michaelblinn commented 11 years ago

These are written but untested:

In Donor class:

In Endowment class:

michaelblinn commented 11 years ago

Diagram of funds movement Processor, investment and sponsor fees not shown img_20130507_155710

michaelblinn commented 11 years ago

The general idea is that endowments (and funds) will have shares and share prices. A donor making a donation into an endowment will be given shares of the endowment, which will track value. The endowment in turn buys shares of a fund (upon transfer to investment platform) to track endowment value. These share prices are computed representations of value generated by giv2giv and updated nightly via cron.

The basic fund value function is: (Assets - Liabilities) / Shares_Outstanding (where shares_outstanding are (shares purchased - shares sold))

fund_share_price = (cash_in_fund + investment_holdings) / fund_shares_outstanding

endowment_share_price = (cash_in_endowment + (fund_share_price * fund_shares_held)) / endowment_shares_outstanding

michaelblinn commented 11 years ago

This work is coming along. I have created models/donation.rb and models/grant.rb

The plan is:

donation.rb deals with the scheduling and completion of incoming donations (donor->endowment via dwolla->giv2giv). It's fairly complete.

There should be a nightly batch that goes through all the completed donations, sorts out how many endowment shares were purchased by each donation, and credits the donor. This is also fairly complete. However, there isn't a quick-and-easy way to find out how many shares of each endowment a donor holds advisory privileges. My thought is to have a relationship from donor->endowment with a shares_advised property that is updated upon a successful donation or grant.

I'm not worrying so much about the right-hand side of the graph that deals with investment funds (models/funds_unused.rb). Once the money is in the endowment we can push it over to eTrade for funds purchasing; the endowment share_price should encompass the underlying funds price. This is functional for only one fund, but will need expansion when we introduce other funds. The only caveat is that the endowment share price will be computing using (endowment_donations_in_dwolla + fund_value)/shares_outstanding

Next task is relationship indexes to easily look up a donor-[DONOR_ADVISED]->endowment relationship to set shares_advised. Neography shows how to do this with phase 1 but not phase 2 which we're trying to stick to.

michaelblinn commented 11 years ago

Just saw this: https://github.com/maxdemarzi/neography/issues/95 "Is there a way to check if there is a relationship between two nodes in Phase 2?"