My first thought would be to create a table in the script that is ordered by date and then team. Then I would load it using inter-row functions like previous() or peek() to keep track of a counter that starts over at 0 for each different team and each time that team loses and adds 1 to the previous row each time the team wins.
There might be a fancier way to do it, but that should get the job done.